package cn.com.controller;

import cn.com.beans.CollegeInfo;
import cn.com.mapper.CollegeInfoMapper;
import cn.com.service.AdmissionInfoService;
import cn.com.service.CollegeInfoService;
import cn.com.service.MajorInfoService;
import cn.com.service.MajorLineService;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/compare")
public class CompareCollegeController {

    @Resource
    private CollegeInfoService collegeInfoService;
    @Resource
    private CollegeInfoMapper collegeInfoMapper;
    @Resource
    private AdmissionInfoService admissionInfoService;
    @Resource
    private MajorInfoService majorInfoService;
    @Resource
    private MajorLineService majorLineService;

    PredictionController predi = new PredictionController();

    @GetMapping("/college")
    public String getcollege() {
        return "compare";
    }

    @PostMapping("/college")
    public void comparecollege() {

    }

//    将后台数据库的所有大学放入前端的弹窗界面
    @GetMapping("/addcollege")
    @ResponseBody
    public JSONArray addcollege(){
        System.out.println("进入了controller");
        List<CollegeInfo> all = collegeInfoService.findAll(null);
        JSONArray jsonArray2 = JSONArray.fromObject(all);
        System.out.println("jsonArray2 = " + jsonArray2);
        return jsonArray2;
    }

    @GetMapping("/chooseschool/{coid}")
    @ResponseBody
    public JSONArray chooseschool(@PathVariable String coid){
        System.out.println("coid = " + coid);
        int i = Integer.parseInt(coid);
        System.out.println("i = " + i);
        CollegeInfo collegeInfo = collegeInfoService.selectByPrimaryKey(i);
        if(collegeInfo != null) {
            JSONArray jsonArray = JSONArray.fromObject(collegeInfo);
            System.out.println("jsonArray = " + jsonArray);
            return jsonArray;
        }else {
            System.out.println("jsonArray为空");
            return null;
        }
    }
}
